//
//  CellOfPicAndPrice.m
//  ProjectA_ManualGuest
//
//  Created by dingcong on 16/6/17.
//  Copyright © 2016年 丁聪. All rights reserved.
//

#import "CellOfPicAndPrice.h"
#import "PrefixHeader.pch"
#import "Masonry.h"
#import "UIImageView+WebCache.h"
@implementation CellOfPicAndPrice

-(void)dealloc{
    
    [_imageOfFirst release];
    [_imageOfSecond release];
    [_imageOfThird release];
    [_lableOfFirst release];
    [_lableOfSecond release];
    [_lableOfThird release];
    [_lableOfFirstPrice release];
    [_lableOfSecondPrice release];
    [_lableOfThirdPrice release];
    [_model release];
    [super dealloc];
    
    
    
    
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        [self creat];
    }
    
    
    
    return self;
}

#pragma mark - cell控件
- (void)creat{
    
    UILabel *lableOfEveryDay = [[UILabel alloc]init];
    
    [self.contentView addSubview:lableOfEveryDay];
    
//    lableOfEveryDay.backgroundColor = [UIColor redColor];
    
    [lableOfEveryDay mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView.mas_top).offset(15);
        make.leading.equalTo(self.contentView.mas_leading).offset(8);
        make.height.offset(20);
        make.width.offset(70);
    }];
    
    
    
    
    lableOfEveryDay.text = @"每日特价";
    lableOfEveryDay.font = [UIFont systemFontOfSize:13];
    [lableOfEveryDay release];
    
    
    UILabel *lableOfUpdate = [[UILabel alloc]init];
    
//    lableOfUpdate.backgroundColor = [UIColor greenColor];
    
    [self.contentView addSubview:lableOfUpdate];
    
    [lableOfUpdate mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(lableOfEveryDay.mas_centerY);
        make.trailing.equalTo(self.contentView.mas_trailing).offset(5);
        make.height.offset(14);
        make.width.offset(60);
        
        
    }];
    
    lableOfUpdate.text = @"每日10:00更新😃";
    lableOfUpdate.font = [UIFont systemFontOfSize:7];
    lableOfUpdate.textColor = [UIColor grayColor];
    [lableOfUpdate release];
    
    
//   1
    self.imageOfFirst = [[UIImageView alloc]init];
    [self.contentView addSubview:self.imageOfFirst];
//    self.imageOfFirst.backgroundColor = [UIColor cyanColor];
    [self.imageOfFirst mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(lableOfEveryDay.mas_bottom).offset(5);
        make.leading.equalTo(self.contentView.mas_leading).offset(8);
        make.width.offset((SCREEN_WIDTH  - 32) / 3);
        make.height.equalTo(self).multipliedBy(1.0 / 2.0);
    }];
    
    [self.imageOfFirst release];
    
    
    
    self.lableOfFirst = [[UILabel alloc]init];
    [self.contentView addSubview:self.lableOfFirst];
//    self.lableOfFirst.backgroundColor = [UIColor redColor];
    
    [self.lableOfFirst mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.imageOfFirst.mas_bottom).offset(5);
        make.leading.equalTo(self.contentView.mas_leading).offset(8);
        make.width.equalTo(self.imageOfFirst.mas_width);
        
    }];
    self.lableOfFirst.font = [UIFont systemFontOfSize:10];
    self.lableOfFirst.textColor = [UIColor grayColor];
    self.lableOfFirst.numberOfLines = 2;
 
    [self.lableOfFirst release];
    
    UIView *lineOfFirst = [[UIView alloc]init];
    
    lineOfFirst.backgroundColor = [UIColor lightGrayColor];
    
    [self.contentView addSubview:lineOfFirst];
    
    [lineOfFirst mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.lableOfFirst.mas_bottom).offset(2);
        make.leading.equalTo(self.contentView.mas_leading).offset(8);
        make.width.equalTo(self.imageOfFirst.mas_width);
        make.height.offset(0.4);
    }];
    
    [lineOfFirst release];
    
    self.lableOfFirstPrice = [[UILabel alloc]init];
    
//    self.lableOfFirstPrice.backgroundColor = [UIColor greenColor];
    self.lableOfFirstPrice.textColor = [UIColor orangeColor];
    [self.contentView addSubview:self.lableOfFirstPrice];
    
    [self.lableOfFirstPrice mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(lineOfFirst.mas_bottom).offset(5);
        make.leading.equalTo(self.contentView.mas_leading).offset(8);
        make.width.equalTo(self.imageOfFirst.mas_width);
        make.height.offset(20);
        
        
        
    }];
    
    [self.lableOfFirstPrice release];
    
//    2
    self.imageOfSecond = [[UIImageView alloc]init];
    [self.contentView addSubview:self.imageOfSecond];
//    self.imageOfSecond.backgroundColor = [UIColor cyanColor];
    [self.imageOfSecond mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.imageOfFirst.mas_centerY);
        make.leading.equalTo(self.imageOfFirst.mas_trailing).offset(8);
        make.width.equalTo(self.imageOfFirst);
        make.height.equalTo(self.imageOfFirst);
    }];
    
    [self.imageOfSecond release];
    
    
    
    self.lableOfSecond = [[UILabel alloc]init];
    [self.contentView addSubview:self.lableOfSecond];
//    self.lableOfSecond.backgroundColor = [UIColor redColor];
    [self.lableOfSecond mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.lableOfFirst.mas_centerY);
        make.leading.equalTo(self.lableOfFirst.mas_trailing).offset(8);
        make.width.offset((SCREEN_WIDTH - 32) / 3);
        
    }];
    self.lableOfSecond.textColor = [UIColor grayColor];
    self.lableOfSecond.font = [UIFont systemFontOfSize:10];
    self.lableOfSecond.numberOfLines = 2;

    [self.lableOfSecond release];

    UIView *lineOfSecond = [[UIView alloc]init];
    
    lineOfSecond.backgroundColor = [UIColor lightGrayColor];
    
    [self.contentView addSubview:lineOfSecond];
    
    [lineOfSecond mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(lineOfFirst.mas_centerY);
        make.leading.equalTo(lineOfFirst.mas_trailing).offset(8);
        make.width.equalTo(self.imageOfFirst.mas_width);
        make.height.offset(0.4);
    }];
    
    [lineOfSecond release];
//
    self.lableOfSecondPrice = [[UILabel alloc]init];
    
//    self.lableOfSecondPrice.backgroundColor = [UIColor greenColor];
    self.lableOfSecondPrice.textColor = [UIColor orangeColor];
    [self.contentView addSubview:self.lableOfSecondPrice];
    
    [self.lableOfSecondPrice mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(lineOfSecond.mas_bottom).offset(5);
        make.leading.equalTo(self.lableOfFirstPrice.mas_trailing).offset(8);
        make.width.equalTo(self.imageOfFirst.mas_width);
        make.height.equalTo(self.lableOfFirstPrice.mas_height);
        
        
        
    }];
    
    [self.lableOfSecondPrice release];
    
    
//    3
    self.imageOfThird = [[UIImageView alloc]init];
    [self.contentView addSubview:self.imageOfThird];
//    self.imageOfThird.backgroundColor = [UIColor cyanColor];
    [self.imageOfThird mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.imageOfFirst.mas_centerY);
        make.leading.equalTo(self.imageOfSecond.mas_trailing).offset(8);
        make.width.equalTo(self.imageOfFirst);
        make.height.equalTo(self.imageOfFirst);
    }];
    
    [self.imageOfThird release];
    
    
    
    self.lableOfThird = [[UILabel alloc]init];
    [self.contentView addSubview:self.lableOfThird];
//    self.lableOfThird.backgroundColor = [UIColor redColor];
    
    [self.lableOfThird mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.lableOfFirst.mas_centerY);
        make.leading.equalTo(self.lableOfSecond.mas_trailing).offset(8);
        make.width.offset((SCREEN_WIDTH - 32) / 3);
        
    }];
    self.lableOfThird.textColor = [UIColor grayColor];
    self.lableOfThird.font = [UIFont systemFontOfSize:10];
    self.lableOfThird.numberOfLines = 2;
    
    [self.lableOfThird release];
//
    UIView *lineOfThird = [[UIView alloc]init];
    
    lineOfThird.backgroundColor = [UIColor lightGrayColor];
    
    [self.contentView addSubview:lineOfThird];
    
    [lineOfThird mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(lineOfFirst.mas_centerY);
        make.leading.equalTo(lineOfSecond.mas_trailing).offset(8);
        make.width.equalTo(self.imageOfFirst.mas_width);
        make.height.offset(0.4);
    }];
    
    [lineOfThird release];
    
    
    
    self.lableOfThirdPrice = [[UILabel alloc]init];
    
//    self.lableOfThirdPrice.backgroundColor = [UIColor greenColor];
    self.lableOfThirdPrice.textColor = [UIColor orangeColor];
    [self.contentView addSubview:self.lableOfThirdPrice];
    
    [self.lableOfThirdPrice mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(lineOfThird.mas_bottom).offset(5);
        make.leading.equalTo(self.lableOfSecondPrice.mas_trailing).offset(8);
        make.width.equalTo(self.imageOfFirst.mas_width);
        make.height.equalTo(self.lableOfFirstPrice.mas_height);
        
        
        
    }];
    
    [self.lableOfThirdPrice release];
    
    
    
}


- (void)setModel:(ModelOfMaterial *)model{

    for (NSInteger i = 0; i < model.arrOfSecond.count; i++) {
        
        NSLog(@"anisdnaionsdionoaisnd:%@", model.arrOfFirst);
        if (i == 0)
        {
            NSURL *url = [[model.arrOfSecond objectAtIndex:i]objectForKey:@"picurl"];
            [self.imageOfFirst sd_setImageWithURL:url placeholderImage:nil];
            
            self.lableOfFirst.text = [[model.arrOfSecond objectAtIndex:i]objectForKey:@"title"];
            NSString *str = @"¥";
            self.lableOfFirstPrice.text =[str stringByAppendingString:[[model.arrOfSecond objectAtIndex:i]objectForKey:@"price"]];
            
            
        }
        else if (i == 1)
        {
            NSURL *url = [[model.arrOfSecond objectAtIndex:i]objectForKey:@"picurl"];
            [self.imageOfSecond sd_setImageWithURL:url placeholderImage:nil];
            self.lableOfSecond.text = [[model.arrOfSecond objectAtIndex:i]objectForKey:@"title"];
            NSString *str = @"¥";
            self.lableOfSecondPrice.text =[str stringByAppendingString:[[model.arrOfSecond objectAtIndex:i]objectForKey:@"price"]];
            
        }
        else if (i == 2)
        {
            NSURL *url = [[model.arrOfSecond objectAtIndex:i]objectForKey:@"picurl"];
            [self.imageOfThird sd_setImageWithURL:url placeholderImage:nil];
            self.lableOfThird.text = [[model.arrOfSecond objectAtIndex:i]objectForKey:@"title"];
            NSString *str = @"¥";
            self.lableOfThirdPrice.text =[str stringByAppendingString:[[model.arrOfSecond objectAtIndex:i]objectForKey:@"price"]];
        }
    }
//    [self.imageOfFirst sd_setImageWithURL:[NSURL URLWithString:model.picurl] placeholderImage:nil];
//    self.lableOfFirst.text = model.title;
//    NSString *str = @"¥";
//    self.lableOfFirstPrice.text = [str stringByAppendingString:model.yh_price];
//    
//    self.lableOfSecond.text = model.title;
}



@end
